package com.morehair.controller.admin;

import com.morehair.bean.pojo.Storage;
import com.morehair.bean.vo.admin.BaseRespVo;
import com.morehair.service.admin.FileService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.io.IOException;
import java.text.ParseException;

/**
 * @Author: DLX
 * @Date: 2021/6/7 15:09
 * @Description:
 **/
@RestController
@RequestMapping("admin/storage")
public class FileController {

    @Autowired
    FileService fileService;

    @RequiresPermissions("admin:storage:create")
    @RequestMapping("create")
    public BaseRespVo fileUpload(@RequestParam("file") MultipartFile multipartFile) throws IOException, ParseException {

        Storage storage = fileService.fileUpload(multipartFile);
        return BaseRespVo.ok(storage);
    }

    @PostMapping("update")
    @RequiresPermissions("admin:storage:update")
    public BaseRespVo updateStorage(@RequestBody Storage storage) {
        Storage storage1=fileService.updateStorage(storage);
        return BaseRespVo.ok(storage1);
    }

    @PostMapping("delete")
    @RequiresPermissions("admin:storage:delete")
    public BaseRespVo deleteStorage(@RequestBody Storage storage) {
        fileService.deleteStorage(storage);
        return BaseRespVo.ok();
    }
}
